/*    */ package com.zimbra.cs.mailclient.pop3;
/*    */ 
/*    */ import com.zimbra.cs.mailclient.MailInputStream;
/*    */ import java.io.EOFException;
/*    */ import java.io.IOException;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class Pop3Response
/*    */ {
/*    */   private final String command;
/*    */   private String status;
/*    */   private String message;
/*    */   private ContentInputStream cis;
/*    */   private static final String OK = "+OK";
/*    */   private static final String ERR = "-ERR";
/*    */   private static final String CONTINUATION = "+";
/*    */   private static final String CAPA = "CAPA";
/*    */   private static final String LIST = "LIST";
/*    */   private static final String RETR = "RETR";
/*    */   private static final String UIDL = "UIDL";
/*    */   
/*    */   public static Pop3Response read(String cmd, MailInputStream is)
/*    */     throws IOException
/*    */   {
/* 43 */     Pop3Response res = new Pop3Response(cmd);
/* 44 */     res.readResponse(is);
/* 45 */     return res;
/*    */   }
/*    */   
/*    */   private Pop3Response(String cmd) {
/* 49 */     this.command = cmd;
/*    */   }
/*    */   
/*    */   private void readResponse(MailInputStream is) throws IOException {
/* 53 */     String line = is.readLine();
/* 54 */     if (line == null) {
/* 55 */       throw new EOFException("Unexpected end of stream");
/*    */     }
/* 57 */     is.trace();
/* 58 */     int i = line.indexOf(' ');
/* 59 */     if (i == -1) {
/* 60 */       this.status = line;
/* 61 */       this.message = "";
/*    */     } else {
/* 63 */       this.status = line.substring(0, i);
/* 64 */       this.message = line.substring(i).trim();
/*    */     }
/* 66 */     if ((isOK()) && (hasContent(this.command))) {
/* 67 */       this.cis = new ContentInputStream(is);
/*    */     }
/*    */   }
/*    */   
/*    */   private static boolean hasContent(String cmd) {
/* 72 */     return ("LIST".equalsIgnoreCase(cmd)) || ("RETR".equalsIgnoreCase(cmd)) || ("UIDL".equalsIgnoreCase(cmd)) || ("CAPA".equalsIgnoreCase(cmd));
/*    */   }
/*    */   
/*    */ 
/* 76 */   public boolean isOK() { return this.status.equals("+OK"); }
/* 77 */   public boolean isERR() { return this.status.equals("-ERR"); }
/* 78 */   public boolean isContinuation() { return this.status.equals("+"); }
/*    */   
/* 80 */   public String getMessage() { return this.message; }
/*    */   
/*    */   public ContentInputStream getContentInputStream() {
/* 83 */     return this.cis;
/*    */   }
/*    */   
/*    */   public void dispose() {
/* 87 */     if (this.cis != null) {
/*    */       try {
/* 89 */         this.cis.close();
/*    */       }
/*    */       catch (IOException e) {}
/*    */     }
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailclient/pop3/Pop3Response.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */